package com.fare.taluo.core.domain.config.channel;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Table;

import com.dayatang.domain.InstanceFactory;
import com.fare.taluo.base.ddd.domain.baseentity.BaseEntity;

/**
 * 抓取网站设置entity
 * @author kelvin_L
 *
 */
@javax.persistence.Entity
@Table(name = "FDC_SOURCE")
@SuppressWarnings("serial")
public class SourceEntity extends BaseEntity {

	@Column(name = "NAME")
	private String name;
	@Column(name = "URL")
	private String url;
	@Column(name = "WEB_TYLE")
	private String webTyle;//网站类型(1.官网，2。代理)
	@Column(name = "CRAWL_STATUS")
	private Integer crawlStatus; //1.表示系统从这些网站抓数；0.表示系统不到这些网站抓数。

	@Column(name="USERID")
	private Long userId;
	
	@Column(name="USER_CREATETIME")
	private Date userCreateTime;
	@Column(name="hbase_key")
	private String hbaseKey;
	@Column(name="carrier_key")
	private String carrierKey;
	@Column(name="short_name")
	private String shortName;

	public String getCarrierKey() {
		return carrierKey;
	}

	public void setCarrierKey(String carrierKey) {
		this.carrierKey = carrierKey;
	}

	public String getWebTyle() {
		return webTyle;
	}

	public void setWebTyle(String webTyle) {
		this.webTyle = webTyle;
	}

	public Integer getCrawlStatus() {
		return crawlStatus;
	}

	public void setCrawlStatus(Integer crawlStatus) {
		this.crawlStatus = crawlStatus;
	}

	public String getShortName() {
		return shortName;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	public Date getUserCreateTime() {
		return userCreateTime;
	}

	public void setUserCreateTime(Date userCreateTime) {
		this.userCreateTime = userCreateTime;
	}

//	public Long getId() {
//		return id;
//	}
//
//	public void setId(Long id) {
//		this.id = id;
//	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	
	private  static SourceEntityRepository getSourceEntityRepository(){
		return InstanceFactory.getInstance(SourceEntityRepository.class);
	}
	/**
	 * 返回查询抓取网站数据
	 * @param name
	 * @param url
	 * @param webTyle 网站类型(1.官网，2。代理)
	 * @return
	 */
	public List<SourceEntity> findSourceEntityListByConditions(String name,String url,String webTyle,String sorttype,int pageNum,int pageSize){
		return getSourceEntityRepository().findSourceEntityListByConditions(name, url, webTyle,sorttype, pageNum, pageSize);
	}
	
	public List<SourceEntity> findSourceEntityListByWbid(String webTyle){
		return getSourceEntityRepository().findSourceEntityListByWbid(webTyle);
	}
	
	public List<SourceEntity> findSourceEntityListByid(Long id){
		return getSourceEntityRepository().findSourceEntityListByid(id);
	}
	/**
	 * 更新
	 * @param id
	 * @param crawlStatus 1.表示系统从这些网站抓数；0.表示系统不到这些网站抓数。
	 */
	public SourceEntity updateSourceEntity(Long id,Integer crawlStatus,Long userId){
		return getSourceEntityRepository().updateSourceEntity(id, crawlStatus, userId);
	}
	
	/**
	 * 返回查询总个数
	 * @param name
	 * @param url
	 * @param webTyle 网站类型(1.官网，2。代理)
	 * @return
	 */
	public int getSourceEntityCount(String name,String url,String webTyle){
		return getSourceEntityRepository().getSourceEntityCount(name, url, webTyle);
	}
	
	public SourceEntity fing(Long id) throws Exception{
		return getSourceEntityRepository().find(id);
	}
	
	public List<SourceEntity> findAllSourceEntity() {
		return getSourceEntityRepository().findAllSourceEntity();
	}

	public String getHbaseKey() {
		return hbaseKey;
	}

	public void setHbaseKey(String hbaseKey) {
		this.hbaseKey = hbaseKey;
	}
	public List<SourceEntity> findSourceEntityListByChanelName(String name){
	    return getSourceEntityRepository().findSourceEntityListByChanelName(name);
	}
	public List<SourceEntity> findSourceEntityByCk(String ck){
		return getSourceEntityRepository().findSourceEntityByCk(ck);
	}
	
	/**
	 * 通过webType查询  0 ,1
	 * */
	public static List<SourceEntity> findBywebType(String webType){
		return getSourceEntityRepository().findSourceEntityListByWbid(webType);
	}
	
	
	public static List<SourceEntity> findByCrawlStatus(int crawlStatus){
		return getSourceEntityRepository().findSourceEntityListByCrawlStatus(crawlStatus);
	}
	
	public List<SourceEntity> findSourceEntityListByLine(String fromCity,String toCity){
		return getSourceEntityRepository().findSourceEntityListByLine(fromCity,toCity);
	}
	
	public List<SourceEntity> findSourceEntityListByCrawlLine(String fromCity,
			String toCity){
		return getSourceEntityRepository().findSourceEntityListByCrawlLine( fromCity,
				 toCity);
	}
	
	public List<SourceEntity> findSourceEntityListByCarrierKey(String carrierKey){
		return getSourceEntityRepository().findSourceEntityListByCarrierKey(carrierKey);
	}
	
	public SourceEntity findByHbaseKey(String hbaseKey){
		return getSourceEntityRepository().findByHbaseKey(hbaseKey);
	}
	
	/**
	 * 找出所有处于抓取状态的航空公司
	 * @return
	 * @throws Exception
	 */
	public List<SourceEntity> findCrawlAirCompany() {
		return getSourceEntityRepository().findCrawlAirCompanys();
	}
	
	/**
	 * 找出所有处于抓取状态的渠道
	 * @return
	 * @throws Exception
	 */
	public static List<SourceEntity> findCrawlChannels() throws Exception{
		return getSourceEntityRepository().findCrawlChannel();
	}

	/**
	 *根据carrierKey找出公司或者渠道
	 * @param carrierKey
	 * @return
	 * @throws Exception
	 */
	public static SourceEntity findCompanyByCarrierKey(String carrierKey) throws Exception{
		List<SourceEntity> ss=getSourceEntityRepository().findSourceEntityListByCarrierKey(carrierKey);
		return (ss==null || ss.isEmpty())?null:ss.get(0);
	}
	
	/**
	 *根据carrierKey找出公司或者渠道
	 * @param carrierKey
	 * @return
	 * @throws Exception
	 */
	public static SourceEntity loadCompanyByCarrierKey(String carrierKey) throws Exception{
		List<SourceEntity> ss=getSourceEntityRepository().findSourceEntityListByCarrierKey(carrierKey);
		return ss.get(0);
	}
	public List<SourceEntity> findByCarrierKey(String carrierKey){
		return getSourceEntityRepository().findByCarrierKey(carrierKey);
	}

}
